package cn.pkubangbang.demo.democontact.controller;

import cn.pkubangbang.demo.democontact.entity.Blog;
import cn.pkubangbang.demo.democontact.entity.Person;
import cn.pkubangbang.demo.democontact.service.BlogService;
import cn.pkubangbang.demo.democontact.service.PersonService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: zhangzhenbang@k2data.com.cn
 * @Date: 2018-09-06 18:18
 */
@Controller
public class BlogController {

    @Autowired
    private BlogService blogService;

    @Autowired
    private PersonService personService;


    @GetMapping("/blog/{userId}")
    @ResponseBody
    public List<Blog> space(@PathVariable("userId") Integer id) {

        Person who = personService.getPersonById(id);
        return blogService.listBlogsOfPerson(who);

    }

    @GetMapping("/home/{userId}")
    @ResponseBody
    public List<Blog> home(@PathVariable("userId") Integer id) {

        Person who = personService.getPersonById(id);
        return blogService.listAllBlogsForPersonAndHisFriends(who);

    }

}
